import pandas as pd

# 读取文本文件
with open('H:\QL_tool_file\Window_Tool\LogicalFile\Batch_Submission/file\log/log.txt', 'r', encoding='utf-8', errors='ignore') as file:
    lines = file.readlines()
# 拆分字段并创建 DataFrame
data = []
for line in lines:
    parts = line.strip().split(',')
    data.append(parts)
max_length = max(len(row) for row in data)
print(max_length)

columns = []
for i in range(1, max_length + 1):
    columns.append("Column" + str(i))
# 创建 DataFrame
df = pd.DataFrame(data, columns=columns)
# 创建 Excel writer 对象
with pd.ExcelWriter('H:\QL_tool_file\Window_Tool\LogicalFile\Batch_Submission/file\log/output.xlsx', engine='openpyxl') as writer:
    # 将数据写入 Excel 表格
    df.to_excel(writer, index=False, sheet_name='Sheet1')

from openpyxl import load_workbook
from openpyxl.styles import PatternFill
# 读取 Excel 文件
wb = load_workbook('H:\QL_tool_file\Window_Tool\LogicalFile\Batch_Submission/file\log/output.xlsx')
# 选择工作表
ws = wb['Sheet1']
# 设置单元格样式
green_fill = PatternFill(fill_type='solid', fgColor='00FF00')
# 遍历单元格并设置颜色
for row in ws.iter_rows():
    for cell in row:
        print ( cell.value )
        if cell.value and '失败' in str(cell.value):
            cell.fill = green_fill
# 保存修改
wb.save('H:\QL_tool_file\Window_Tool\LogicalFile\Batch_Submission/file\log/output.xlsx')